"""
@File    :   models.py
@Time    :   2024/02/19 14:27:14
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   社交登录用户数据模型
"""

from datetime import datetime

from sqlalchemy import BigInteger, Column, DateTime, Integer, String

from src.models.models import OrmBase


class SocialUser(OrmBase):
    """社交登录用户数据模型"""

    __tablename__ = "system_social_user"
    id = Column(BigInteger(), primary_key=True, autoincrement=True, comment="主键")
    create_datetime = Column(
        DateTime(), nullable=False, default=datetime.now, index=True, comment="创建时间"
    )
    update_datetime = Column(
        DateTime(),
        nullable=False,
        default=datetime.now,
        onupdate=datetime.now,
        index=True,
        comment="修改时间",
    )
    # 租户ID(级联删除)
    tenant_id = Column(BigInteger(), nullable=False, index=True, comment="租户ID")
    social_type = Column(String(100), nullable=False, comment="社交平台类型")
    openid = Column(String(50), nullable=False, comment="社交openid")
    token = Column(String(256), nullable=False, comment="社交Token")
    social_name = Column(String(50), nullable=False, comment="社交名称")
    social_avatar = Column(String(300), default="", nullable=False, comment="社交头像")
    raw_token = Column(
        String(1024), nullable=False, comment="原始的社交Token数据"
    )  # 一般是Json格式
    raw_user_info = Column(
        String(1024), nullable=False, comment="原始的社交用户数据"
    )  # 一般为Json格式
    last_auth_code = Column(
        String(256), default="", nullable=False, comment="最后一次的认证code"
    )
    last_auth_state = Column(
        String(256), default="", nullable=False, comment="最后一次的认证state"
    )
